package com.panfeng.xcloud.common.core.support;

import com.panfeng.xcloud.common.core.component.SnowflakeIdWorker;
import com.panfeng.xcloud.common.core.utils.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.UUID;

/**
 * 业务base service
 *
 * @author xiaobo
 * @version 1.0
 * @since 2018-12-28
 */
public abstract class BaseService {

	protected final Logger logger = LoggerFactory.getLogger(this.getClass());

	protected long generateId() {
		SnowflakeIdWorker snowflakeIdWorker = SpringContextUtil.getApplicationContext().getBean(SnowflakeIdWorker.class);
		if(null != snowflakeIdWorker){
			logger.info(">>> 雪花算法生成唯一标识<<<");
			return snowflakeIdWorker.nextId();
		}
		return UUID.randomUUID().timestamp();
	}
}
